import 'package:bitcoin_mine/widgets/restore_purchases_section.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/subscription_controller.dart';
import '../widgets/subscription_tier_tabs.dart';
import '../widgets/subscription_plan_cards.dart';
import '../widgets/subscription_bottom_bar.dart';
import '../l10n/app_localizations.dart';

class SubscriptionPage extends StatelessWidget {
  const SubscriptionPage({super.key});

  @override
  Widget build(BuildContext context) {
    // 初始化订阅控制器
    Get.put(SubscriptionController());

    final l10n = AppLocalizations.of(context);

    return Scaffold(
      backgroundColor: const Color(0xFF0A0E27),
      body: Stack(
        children: [
          // 背景图片
          Image.asset(
            'assets/images/pic_contract_bg.png',
            fit: BoxFit.cover,
            width: double.infinity,
            height: double.infinity,
          ),

          // 主要内容
          Column(
            children: [
              // 安全区域
              SafeArea(bottom: false, child: Container()),

              // 头部
              _buildHeader(l10n),

              SizedBox(height: 20.h),

              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      // 订阅层级选择
                      const SubscriptionTierTabs(),

                      // 订阅计划选择
                      const SubscriptionPlanCards(),

                      SizedBox(height: 20.h),
                      // // 恢复购买按钮
                      // const RestorePurchasesButton(),

                      // SizedBox(height: 20.h),

                      // 恢复购买说明
                      const RestorePurchasesSection(),

                      SizedBox(height: 90.h),
                    ],
                  ),
                ),
              ),
            ],
          ),

          // 底部订阅栏
          Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: const SubscriptionBottomBar(),
          ),
        ],
      ),
    );
  }

  Widget _buildHeader(AppLocalizations l10n) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
      child: Row(
        children: [
          // 返回按钮
          GestureDetector(
            onTap: () => Get.back(),
            child: SizedBox(
              width: 40.w,
              height: 40.w,
              child: Icon(
                Icons.arrow_back_ios,
                color: Colors.white,
                size: 20.sp,
              ),
            ),
          ),

          SizedBox(width: 16.w),

          // 标题
          Expanded(
            child: Text(
              l10n.membershipSubscription,
              style: TextStyle(
                color: Colors.white,
                fontSize: 20.sp,
                fontWeight: FontWeight.bold,
              ),
              textAlign: TextAlign.center,
            ),
          ),

          // 占位符，保持标题居中
          SizedBox(width: 56.w),
        ],
      ),
    );
  }
}
